import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

index = [
    {'name': '张三', 'pwd': 11, 'telA': '12345678900', 'emailA': '12345678900@qq.com'},
    {'name': '李四', 'pwd': 22, 'telA': '12345678901', 'emailA': '12345678901@qq.com'},
    {'name': '王五', 'pwd': 33, 'telA': '12345678902', 'emailA': '12345678902@qq.com'}
]


# 2.打开浏览器（创建浏览器驱动对象）
driver = webdriver.Chrome()
# 3.输入网址
driver.get("http://121.43.169.97:8848/pageA.html")
# 4.页面操作:通过ID属性定位页面元素
# 4.1定位元素并输入内容
# driver.find_element(by=By.ID,value="userA").send_keys("admin")
# driver.find_element(by=By.ID,value="passwordA").send_keys("123456")
# driver.find_element(by=By.NAME,value="telA").send_keys("12345678900")
# driver.find_element(by=By.CLASS_NAME,value="emailA").send_keys("123456@qq.com")
# driver.find_element(By.LINK_TEXT,"百度").click()

for i in index:
    driver.get("http://121.43.169.97:8848/pageA.html")

    driver.find_element(by=By.ID,value="userA").send_keys(i.get('name'))
    driver.find_element(by=By.ID,value="passwordA").send_keys(i.get('pwd'))
    driver.find_element(by=By.NAME,value="telA").send_keys(i.get('telA'))
    driver.find_element(by=By.CLASS_NAME,value="emailA").send_keys(i.get('emailA'))
    driver.find_element(by=By.TAG_NAME, value="button").click()

    time.sleep(3)

# 模拟用户操作
# 获取用户名：通过标签ID、标签属性、标签class、标签名
# driver.find_element(By.CSS_SELECTOR, "#userA").send_keys("admin") # id属性值
# driver.find_element(By.CSS_SELECTOR, "[name='passwordA']").send_keys("123456") # 标签属性
# driver.find_element(By.CSS_SELECTOR, ".telA").send_keys("13800000001") # class属性值
# # 输入邮箱信息：多个class值，通过点号连接
# driver.find_element(by=By.CSS_SELECTOR, value=".emailA.dzyxA").send_keys("123456@qq.com")
# driver.find_element(By.CSS_SELECTOR, "button").click() # 标签名

# driver.find_element(By.CSS_SELECTOR,"p>input").send_keys("admin") # 父子关系
# driver.find_element(By.CSS_SELECTOR,"form input").send_keys("test") # 上下级关系
# driver.find_element(By.CSS_SELECTOR,"input[id*='pass']").send_keys("123456") # 元素和属性模糊匹配扩展

driver.maximize_window()
# 5.等待2秒
time.sleep(3)
# 6.退出浏览器
driver.quit()